package com.tanhua.controller;

import com.tanhua.Intercepter.UserHolder;
import com.tanhua.exception.BusinessExecption;
import com.tanhua.model.domain.ErrorResult;
import com.tanhua.model.domain.UserInfo;
import com.tanhua.service.UserInfoService;
import com.tanhua.service.UserService;
import com.tanhua.utils.JwtUtils;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private UserInfoService userInfoService;

    /**
     * 完善用户信息
     *
     * @param userInfo
     * @return
     */
    @PostMapping("/loginReginfo")
    public ResponseEntity loginReginfo(@RequestBody UserInfo userInfo) {
        //向userInfo设置id
        userInfo.setId(Long.valueOf(UserHolder.getId()));
        //调用service
        userInfoService.save(userInfo);
        return ResponseEntity.ok(null);
    }

    /**
     * 完善用户头像
     *
     * @param headphoto
     * @return
     * @throws IOException
     */
    @PutMapping("/loginReginfo/head")
    public ResponseEntity updateUserInfo(MultipartFile headphoto) throws IOException {
        userInfoService.updateHead(headphoto, UserHolder.getId());
        return ResponseEntity.ok(null);
    }
}
